<!DOCTYPE html>
<html lang="en">
<title>验证码管理-验证码列表</title>
<#import "/layout/layout.html" as body/>
<@body.page>

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5 class="pull-left">验证码列表</h5>
                </div>
                <div class="ibox-content">
                    <div class="table-responsive">
                        <form class="form-inline" role="form">
                            <div class="form-group">
                                <label for="mobile">手机号：</label>
                                <input class="form-control" type="text" id="mobile" name="mobile"/>
                            </div>
                            <button type="button" id="search" class="btn btn-outline btn-primary" style="margin-top: 5px">确认</button>
                        </form>
                        <hr>
                        <table class="table table-hover table-center dataTables-example">
                            <thead>
                            <tr>
                                <th>用户ID</th>
                                <th>用户昵称</th>
                                <th>手机号</th>
                                <th>验证码</th>
                                <th>心跳异常门店</th>
                                <th>企业名称</th>
                                <th>发送类型</th>
                                <th>发送时间</th>
                                <th>发送结果</th>
                            </tr>
                            </thead>
                            <tbody id="smslog_list">
                            </tbody>
                        </table>
                    </div>

                </div>
                <div class="ibox-footer overflow">
                    <h4 class="pull-left">合计：<span id="userCount">0</span>条验证码</h4>
                    <div id="copot-page" class="pull-right"></div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    $(document).ready(function () {

        Date.prototype.pattern = function (fmt) {
            var o = {
                "M+": this.getMonth() + 1, //月份
                "d+": this.getDate(), //日
                "h+": this.getHours() % 12 == 0 ? 12 : this.getHours() % 12, //小时
                "H+": this.getHours(), //小时
                "m+": this.getMinutes(), //分
                "s+": this.getSeconds(), //秒
                "q+": Math.floor((this.getMonth() + 3) / 3), //季度
                "S": this.getMilliseconds() //毫秒
            };
            var week = {
                "0": "/u65e5",
                "1": "/u4e00",
                "2": "/u4e8c",
                "3": "/u4e09",
                "4": "/u56db",
                "5": "/u4e94",
                "6": "/u516d"
            };
            if (/(y+)/.test(fmt)) {
                fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
            }
            if (/(E+)/.test(fmt)) {
                fmt = fmt.replace(RegExp.$1, ((RegExp.$1.length > 1) ? (RegExp.$1.length > 2 ? "/u661f/u671f" : "/u5468") : "") + week[this.getDay() + ""]);
            }
            for (var k in o) {
                if (new RegExp("(" + k + ")").test(fmt)) {
                    fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
                }
            }
            var str = fmt.lastIndexOf("N");
            if (str != -1) {
                return "";
            }

            return fmt;
        }

        smslog_list(1);

        $("#search").click(function () {
            smslog_list(1);
        });
    });

    function Trim(str, is_global) {
        var result;
        result = str.replace(/(^\s+)|(\s+$)/g, "");
        if (is_global.toLowerCase() == "g")
            result = result.replace(/\s/g, "");
        return result;
    }

    function smslog_list(currentIndex) {
        $("#smslog_list").empty();
        var mobile = Trim($("#mobile").val(), 'g');
        $.ajax({
            url: "${baseUrl}/system/smslog/smslog_list?pageIndex=" + currentIndex + "&pageSize=" + 10 + "&mobile=" + mobile,
            type: "POST",
            success: function (result) {
                debugger
                var html = "";
                //分页
                new Page({
                    parent: $("#copot-page"),
                    nowPage: currentIndex,
                    pageSize: 10,
                    totalCount: result.count,
                    setting: {
                        defaultPage: 7,//默认显示可点击分页的个数
                        firstPageText: "首页",
                        prevPageText: "上一页",
                        nextPageText: "下一页",
                        lastPageText: "尾页"
                    },
                    callback: function (nowPage, totalPage) {
                        smslog_list(nowPage);
                    }
                });

                $("#userCount").text(result.count);
                var userId = null;
                var nickName = null;
                var sendTime = null;
                var sendResult = null;
                var sendType = null;
                var checkCode = null;
                var storeName = null;
                var companyName = null;
                $.each(result.list, function (i, result) {
                    if (result){
                        debugger
                        if(result.userId == -1){
                            userId = "系统";
                        } else {
                            userId = result.userId;
                        }
                        if(result.nickName){
                            nickName = result.nickName;
                        } else {
                            nickName = "无数据";
                        }
                        if(result.sendTime){
                            sendTime = new Date(result.sendTime).pattern("yyyy-MM-dd HH:mm:ss");
                        } else {
                            sendTime = "异常";
                        }
                        if(result.sendResult == 0){
                            sendResult = "失败";
                        } else if(result.sendResult == 1){
                            sendResult = "成功";
                        } else {
                            sendResult = "异常";
                        }
                        if(result.sendType == 1){
                            sendType = "验证码";
                        }else if(result.sendType == 2){
                            sendType = "门禁异常心跳";
                        }else if(result.sendType == 3){
                            sendType = "企业余额通知";
                        } else {
                            sendType = "异常";
                        }
                        if(result.checkCode){
                            checkCode = result.checkCode;
                        } else {
                            checkCode = "无";
                        }
                        if(result.storeName){
                            storeName = result.storeName;
                        } else {
                            storeName = "无";
                        }

                        if(result.companyName){
                            companyName = result.companyName;
                        } else {
                            companyName = "无";
                        }

                    }
                    html += "<tr><td>" + userId + "</td>";
                    html += "<td>" + nickName + "</td>";
                    html += "<td>" + result.mobile + "</td>";
                    html += "<td>" + checkCode + "</td>";
                    html += "<td>" + storeName + "</td>";
                    html += "<td>" + companyName + "</td>";
                    html += "<td>" + sendType + "</td>";
                    html += "<td>" + sendTime + "</td>";
                    html += "<td>" + sendResult+ "</td>";
                    html += "</tr>";
                });
                $("#smslog_list").html(html);
                //导出excel
                // ExampleFile("用户excel");
            }
        });
    }
</script>
</@body.page>
</html>